;(function(global,factory){
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = global || self, global.flexible = factory());
}(this,function(){
    let flexible = {
        resizeEvt:'orientationchange' in window ? 'orientationchange' : 'resize'
    }
    ,doc = document;
    flexible.setRootFontSize = function(layoutWidth){
        //浅拷贝
        let rootFontSize = 100 * (layoutWidth / 750)
        Object.assign(flexible,{
            layoutWidth:layoutWidth
            ,dpr:window.devicePixelRatio
            ,fontSize:rootFontSize < 100 ? rootFontSize : 100 
        })
        doc.documentElement.style.fontSize = flexible.fontSize +'px'
    }

    flexible.px2rem = function(px){
      return px/flexible.fontSize;
    }

    flexible.ready = function(){
        let _self = this,layoutWidth = doc.documentElement.clientWidth;
        doc.addEventListener('DOMContentLoaded',function(){
            _self.setRootFontSize(layoutWidth)
        });
        window.addEventListener(_self.resizeEvt,function(){
            _self.setRootFontSize(doc.documentElement.clientWidth)
        })
        _self.setRootFontSize(layoutWidth)
    }.call(flexible);
    return flexible;
}));